package com.antd.admin.server.strategy.data;

import com.antd.admin.api.dto.RoleDTO;
import com.antd.admin.server.service.ISysDeptService;
import com.antd.common.data.enums.DataScopeTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author: 冷言丶冷语
 * @create: 2020-10-27 10:52
 */
@Component("4")
public class CustomizeDataScope implements AbstractDataScopeHandler{
    @Autowired
    private ISysDeptService deptService;
    @Override
    public List<String> getDeptIds(RoleDTO roleDto, DataScopeTypeEnum dataScopeTypeEnum) {
        List<String> roleDeptIds = roleDto.getRoleDepts();
        List<String> ids = new ArrayList<>();
        for (String deptId : roleDeptIds) {
            ids.addAll(deptService.queryDeptIds(deptId));
        }
        Set<String> set = new HashSet<>(ids);
        ids.clear();
        ids.addAll(set);
        return ids;
    }
}
